

jQuery(function ($) {
    var user_info = JSON.parse(localStorage.getItem('user_info'));
    if (!user_info) {
        window.location.href = "/login/login.html";
    }
    var url = window.location.search;
    if (!url) {
        return;
    };
    var values = url.split("=")[1];
    var param = {
        'Order': {
            'id': values
        },
        '[]': {
            'OrderDelivery': {
                'order_id': values
            },
            'OrderDeliveryGoods[]': {
                'OrderDeliveryGoods': {
                    'delivery_id@': '[]/OrderDelivery/id',
                    'OrderGoods': {
                        'id@': '/goods_id'
                    }
                }
            }
        }
    };
    send_ajax('post', '/get', param, function (data) {
        if (data.code == 200) {
            var maxMoney = data.Order.total_amt;
            var time = data.Order.create_time.split('.')[0];
            var orderSn = data.Order.order_sn;
            var html = "";
            $('#order_sn').text(orderSn);
            $('#order_time').text(time);
            $('#order_p').text(maxMoney);

            var orderGoods = [];
            var orderServiceGoods = [];
            var html = "";
            for (var i = 0; i < data["[]"].length; i++) {
                orderGoods.push(data["[]"][i]);
            }
            for (var n = 0; n < orderGoods.length; n++) {
                if (orderGoods[n]["OrderDeliveryGoods[]"]) {
                    for (var j = 0; j < orderGoods[n]["OrderDeliveryGoods[]"].length; j++) {
                        orderServiceGoods.push(orderGoods[n]["OrderDeliveryGoods[]"][j]);
                    }
                }
            }
            for (var k = 0; k < orderServiceGoods.length; k++) {
                html += '  <div class="evaluate_box">\n                            <div class="content_left">\n                                <a href="/goods-'+orderServiceGoods[k].OrderGoods.id+'.html" class="pic" target="_blank"><img src="' + isImgHttp(orderServiceGoods[k].OrderGoods.thumb) + '" alt=""></a>\n                                <a href="/goods-'+orderServiceGoods[k].OrderGoods.id+'.html" class="msg" target="_blank">' + orderServiceGoods[k].OrderGoods.goods_name + "</a>\n                            </div>\n                            <div class=\"content_right\">\n                                <textarea class=\"txt\" placeholder=\"\u8BF7\u60A8\u505A\u51FA\u771F\u5B9E\u8BC4\u4EF7~ \" maxlength=\"500\" ></textarea>\n                                <span class=\"txt_num\"> <span class=\"text_count\">0</span>/500</span>\n                                <!-- <div class=\"evaluated_status1\">\n                                    <div class=\"evaluate_pic\">\n                                        <img src=\"\" alt=\"\">\n                                        <img src=\"\" alt=\"\">\n                                    </div>\n                                    <div class=\"evaluated\">\n                                        <a>\u5DF2\u8BC4\u4EF7</a>\n                                    </div>\n                                </div> -->\n                                <div class=\"evaluated_status2\">\n                                    <div class=\"service_type\">\n                                        <div class=\"choose_type imgshow\">\n                                            <div class=\"img_box\"></div>\n                                            <div class=\"img_upload\">\n                                            </div>\n                                            <input type=\"file\" class=\"file\" name=\"file\">\n                                            <span class=\"more_upload\">\u5171<span class=\"num total_count\">0</span>\u5F20\uFF0C\u6700\u591A<span class=\"num max_count\" id >5</span>\u5F20</span>\n                                        </div>\n                                    </div>\n                                </div>\n                            </div>\n                        </div>\n                ";
            }
            $('.evaluate_content').html(html);
            //晒图
            $(".img_upload").click(function () {
                var _this = $(this).parents('.choose_type ');
                _this.find(".file").click(); //隐藏了input:file样式后，点击头像就可以本地上传
                _this.find(".file").on("change", function () {
                    var $filePath = URL.createObjectURL(_this.find("input[name='file']")[0].files[0]);
                    var formData = new FormData();
                    formData.append("image", _this.find("input[name='file']")[0].files[0]);
                    $.ajax({
                        url: host + "/api/upload/img/2",
                        type: 'POST',
                        data: formData,
                        cache: false,
                        // // 告诉jQuery不要去处理发送的数据
                        processData: false,
                        // 告诉jQuery不要去设置Content-Type请求头
                        contentType: false,
                        beforeSend: function beforeSend() {},
                        success: function success(data) {
                            if (data.code == 200) {
                                $('.file').val(''); //解决不能同时上传同一张图片
                                _this.find('.img_box').append('<div class="img_list">\n                                                        <img src="' + $filePath + '" alt="">\n                                                        <span class="de_img"><i class="deleteImg"></i></span>\n                                                </div>');
                                _this.find('.total_count').text(_this.find('.img_list').length);
                                if (_this.find('.total_count').html() >= 5) {
                                    _this.find('.img_upload').hide();
                                }
                                $('.img_list').mouseenter(function () {
                                    $(this).find('.de_img').show();
                                }).mouseleave(function () {
                                    $(this).find('.de_img').hide();
                                });
                                $(".file").unbind();
                            } else {
                                alert(data.msg);
                            }
                        },
                        error: function error(data) {
                            alert('网络加载失败，请稍候再试!');
                        }
                    });
                });
            });
            /*字数限制*/
            $(".txt").on("input propertychange", function () {
                var count = $(this).val().length;
                var num_box = $(this).parent('.content_right').find('.text_count');
                num_box.html(count);
            });
        }
    });
    $(document).on('click', '.deleteImg', function () {
        var _thisParent = $(this).parents('.img_list').parent('.img_box');
        $(this).parents('.img_list').remove();
        var imgLength = _thisParent.find('.img_list').length;
        _thisParent.parents('.choose_type').find('.total_count').text(imgLength);
        if (imgLength < 5) {
            _thisParent.parents('.choose_type').find('.img_upload').show();
        }
    });
    //是不说匿名评论
    $('.anonymous i').click(function () {
        if ($(this).hasClass('isanonymous2')) {
            $(this).removeClass('isanonymous2').addClass('isanonymous1');
        } else {
            $(this).addClass('isanonymous2').removeClass('isanonymous1');
        }
    });
});